# https://www.jianshu.com/p/d7b67051fe86

from qiniu import Auth, put_file
import qiniu.config
import glob2
import os

access_key = '954-PH1tShNDppTvXjh6v-HAunL45MzZPqAWGP35'
secret_key = 'mkCGvQqyvr28XgH9RSvbMKKukmrM4z0s9VBeDUCs'

q = Auth(access_key, secret_key)

bucket_name = 'learnerhub_vue'

resources = glob2.glob('dist/static/**')
def upload(path):
    file_name = path.replace('dist/', '')
    key = file_name
    token = q.upload_token(bucket_name, key, 3600)
    localfile = './' + path
    put_file(token, key, localfile)

for r in resources:
    if os.path.isfile(r):
      s = r.replace('\\','/')
      print(s)
      upload(s)
